<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'

// 表单数据模型
const form = reactive({
  username: '',
  password: '',
  phone: '',
  email: '',
  userType: 'PUBLIC',
  realName: '',
  idCard: '',
  avatar: ''
})

// 文件列表（用于头像上传）
const avatarFileList = ref([])

// 提交事件
const onSubmit = () => {
  console.log('提交的数据:', form)
  ElMessage.success('提交成功！')
}

// 重置事件
const onReset = () => {
  form.username = ''
  form.password = ''
  form.phone = ''
  form.email = ''
  form.userType = 'PUBLIC'
  form.realName = ''
  form.idCard = ''
  form.avatar = ''
  avatarFileList.value = []
  ElMessage.info('表单已重置')
}


</script>
<template>
  <el-form :model="form" label-width="120px" style="max-width: 600px">
    <!-- 用户名 -->
    <el-form-item label="用户名">
      <el-input v-model="form.username" placeholder="请输入用户名" />
    </el-form-item>

    <!-- 密码 -->
    <el-form-item label="密码">
      <el-input v-model="form.password" type="password" show-password placeholder="请输入密码" />
    </el-form-item>

    <!-- 真实姓名 -->
    <el-form-item label="真实姓名">
      <el-input v-model="form.realName" placeholder="请输入真实姓名" />
    </el-form-item>

    <!-- 手机号 -->
    <el-form-item label="手机号">
      <el-input v-model="form.phone" placeholder="请输入手机号" />
    </el-form-item>

    <!-- 邮箱 -->
    <el-form-item label="邮箱">
      <el-input v-model="form.email" placeholder="请输入邮箱地址" />
    </el-form-item>

    <!-- 身份证号 -->
    <el-form-item label="身份证号">
      <el-input v-model="form.idCard" placeholder="请输入身份证号码" />
    </el-form-item>


    <!-- 头像上传 -->
    <el-form-item label="头像">
      <el-input v-model="form.avatar" type="file" ></el-input>
    </el-form-item>

    <!-- 提交按钮 -->
    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
      <el-button @click="onReset">重置</el-button>
    </el-form-item>
  </el-form>
</template>



<style scoped>
.el-form {
  margin-top: 20px;
}
.el-form-item {
  margin-bottom: 20px;
}
.el-upload-list__item {
  display: none;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #f5f5f5;
  border-radius: 50%;
  border: 1px solid #ddd;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  &:hover {
    background-color: #ddd;
    border-color: #aaa;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
    z-index: 1;
  }
}
.el-upload-list__item-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.el-upload-list__item-actions {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  opacity: 0;
  transition: opacity 0.3s ease;
  &:hover {
    opacity: 1;
    cursor: pointer;
    .el-icon-delete {
      color: red;
      transition: color 0.3s ease;
    }
  }
}
</style>
